package com.hzlj.position.locate.common.dto.position;

import com.fz.common.dict.annotation.Dict;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * 添加位置的返回
 **/
@Data
@ToString
public class PositionAddResultDTO {
    private int code;
    private String msg;
    private Object data;
    @Dict
    private PositionQueryResultDTO position;


    public PositionAddResultDTO() {

    }

    @SuppressWarnings("unchecked")
    public PositionAddResultDTO addData(Object value) {
        if (data == null) {
            data = Lists.newArrayList();
        }
        if( data instanceof List){
            ((List<Object>) data).add(value);
        }
        return this;
    }
    public PositionAddResultDTO setData(Object value) {
        this.data=value;
        return this;
    }

    public static PositionAddResultDTO success() {
        return success(null);
    }

    public static PositionAddResultDTO success(String msg) {
        PositionAddResultDTO position = new PositionAddResultDTO();
        position.setCode(0);
        position.setMsg(msg);
        return position;
    }

    public static PositionAddResultDTO fail(String msg) {
        PositionAddResultDTO position = new PositionAddResultDTO();
        position.setCode(100);
        position.setMsg(msg);
        return position;
    }

    public boolean isSuccess() {
        return this.code == 0;
    }
}
